package besteAukera;

import java.awt.Color;
import java.awt.Graphics;
import java.util.Vector;

public class Equ extends AteLogikoak {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Hanka s1, s2, i1;
	private Color kolorea;
	private Vector<Hanka> hankaBektorea = new Vector<Hanka>();
	private Vector<Hanka> sarreraBektorea = new Vector<Hanka>();
/**
 * Behar dituen parametroak pasata Equ logikoa eta And, Or, Nor eta Nand
	 * fisikoak sortzeko eraikitzailea.
	 * 
	 * @param x1
	 *            :Equ logikoaren irudiko elipsearen ezker iskineko x
	 *            koordenatua.
	 * @param y1
	 *            :Equ logikoaren irudiko elipsearen goiko iskineko y
	 *            koordenatua.
	 * @param hankaKop
	 *            :Equ-aren hanka kopurua.
	 * @param sarKop
	 *            :Equ-aren sarrera kopurua.
	 * @param motaFis 
	 * 			  :Hankak marrazterakoan zein Equ fisiko den jakiteko.
	 * @param kolorea
 */
	
	public Equ(int x1, int y1, int hankaKop, int sarKop, String motaFis, Color kolorea) {
		super(x1, y1, hankaKop, sarKop,motaFis, kolorea );
		// TODO Auto-generated constructor stub

		if (motaFisikoa.compareTo("1") == 0) {
			s1 = new Hanka(x + 11, y + 50/4, "positiboa", "s", 0, this,
					"h", "ez",true);
			s2 = new Hanka(x + 11, y + 50 - 50/4, "positiboa", "s", 1,
					this, "h", "ez",true);
			i1 = new Hanka(x + 90, y + 25, "negatiboa", "i", 2,
					this, "h", "ez",true);
		} else if (motaFisikoa.compareTo("2") == 0) {
			s1 = new Hanka(x + 12, y + 12, "negatiboa", "s", 0, this, "h", "ez",true);
			s2 = new Hanka(x + 12, y + 36, "positiboa", "s", 1, this, "h", "ez",true);
			i1 = new Hanka(x + 90, y + 24, "positiboa", "i", 2, this,
					"h", "ez",true);
		} else if (motaFisikoa.compareTo("3") == 0) {
			s1 = new Hanka(x + 11, y + 12, "positiboa", "s", 0, this, "h", "ez",true);
			s2 = new Hanka(x + 11, y + 36, "negatiboa", "s", 1, this, "h", "ez",true);
			i1 = new Hanka(x + 90, y + 24, "positiboa", "i", 2, this, "h",
					"ez",true);
		} else if (motaFisikoa.compareTo("4") == 0) {
			s1 = new Hanka(x + 12, y + 12, "negatiboa", "s", 0, this, "h", "ez",true);
			s2 = new Hanka(x + 12, y + 36, "negatiboa", "s", 1, this, "h", "ez",true);
			i1 = new Hanka(x + 90, y + 24, "negatiboa", "i", 2, this, "h",
					"ez",true);
		}

		lotList[0] = s1;
		lotList[1] = s2;
		lotList[2] = i1;
	}
	/**
	 * Equ txiparen irteerako hankari equ eragiketa logikoaren balioa
	 * emango dio:
	 * 
	 * 1equ1=1
	 * 1equ0=0
	 * 0equ1=0
	 * 0equ0=0
	 * 
	 * @param Equ-aren sarrerako biten balioa
	 */
	@Override
	public void funtzioLogikoa(Integer... values) {

		// TODO Auto-generated method stub

		lotList[2].getIrteera().setBalioa(
				this.equ(s1.getSarrera().getBalioa(), s2.getSarrera()
						.getBalioa()));

	}
/**
 * Equ funtzioaren emaitzak kalkulatzen ditu.
 * 
 * @param s1 :Lehen bitaren balioa
 * @param s2 :Bigarren bitaren balioa
 * @return :eragiketaren emaitza
 */
	public Integer equ(Integer s1, Integer s2) {
		if (s1.equals(s2))
			return 1;
		else
			return 0;
	}
	/**
	 * Equ txipeko hankak hankaBektorea Vector-en sartzen du.
	 * 
	 * @return Equ txiparen hanken bektorea
	 */
	@Override
	public Vector<Hanka> getHankak() {
		// TODO Auto-generated method stub
		hankaBektorea = new Vector<Hanka>();
		hankaBektorea.addElement(s1);
		hankaBektorea.addElement(s2);
		hankaBektorea.addElement(i1);
		return hankaBektorea;
	}
	/**
	 * Equ txipa marrazten du.
	 */
	public void marraztu(Graphics g) {

		if (getAukeratua() == true) {
			kolorea = Color.GRAY;
		} else {
			kolorea = Color.black;
		}
		g.setColor(kolorea);
		g.drawArc(x, y, 70, 50, 270, 180);
		g.drawLine(x + 35 - 3, y, x + 32, y + 50);
		g.drawLine(x + 35, y, x + 35, y + 50);
		s1.marraztu(g);
		s2.marraztu(g);
		i1.marraztu(g);
	}
	/**
	 * Equ txipeko sarrerako hankak hankaBektorea Vector-en 
	 * sartzen du.
	 * 
	 * @return Equ txiparen sarrera hanken bektorea
	 */
	@Override
	public Vector<Hanka> getSarreraHankak() {
		// TODO Auto-generated method stub
		sarreraBektorea = new Vector<Hanka>();
		sarreraBektorea.addElement(s1);
		sarreraBektorea.addElement(s2);
		return sarreraBektorea;
	}

}
